﻿using System.Web.Mvc;
using IBBI.DataBase;
using IBBI.DataBase.Obj;
using Web.Models.Common;
using Web.Models.Security;

namespace Web.Areas.Private.Controllers {

    public class LogInServiceXController : AbstractPrivateController {

        [HttpPost]
        public JsonResult LogIn(LogInModel model) {
            var response = Locate<IUserService>().Authenticate(new AuthenticateRequest {
                Email    = model.Email,
                Password = model.Password
            });

            return JSONResponse.CreateResponse(new Session {
                   UserId    = response.User.Id,
                   Email     = response.User.Email,
                   FirstName = response.User.FirstName,
                   LastName  = response.User.LastName,
                   Role      = response.User.Role,
                   Passport  = PassportUtil.WritePassport(response.User)
            });
        }

    }

}
